<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <!-- <blockquote class="layui-elem-quote layui-text">
             鉴于小伙伴的普遍反馈，先温馨提醒两个常见“问题”：1. <a href="/doc/base/faq.html#form" target="_blank">为什么select/checkbox/radio没显示？</a> 2. <a href="/doc/modules/form.html#render" target="_blank">动态添加的表单元素如何更新？</a>
         </blockquote>-->

        <!-- <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
             <legend>表单集合演示</legend>
         </fieldset>-->


        <form class="layui-form" lay-filter="register">

            <div class="layui-form-item">

                <label class="layui-form-label">会员类型:</label>
                <div class="layui-input-inline" lay-filter="roleName">
                    <select name="roleId" id="roleId">
                        <option value=""></option>
                    </select>
                </div>

                <label class="layui-form-label">密码:</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">用户名 :</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="username" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>

                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">真实姓名:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="realName" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">证件类型:</label>
                    <div class="layui-input-inline">
                        <select name="cardTypeName" id="cardTypeName">
                            <option value=""></option>
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">证件号码:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="idCard" lay-verify="identity" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">电子邮件</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="email" lay-verify="required|email" autocomplete="off"
                               class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">邮政编码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="postCode" lay-verify="number" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">推荐人 :</label>
                    <div class="layui-input-inline" lay-filter="refer">
                        <select name="referId" id="refer">
                            <option value=""></option>
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">移动电话:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="mobile" lay-verify="phone" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">收货国家:</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="country" lay-verify="required" autocomplete="off"
                               class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">二级密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="password2" lay-verify="required" autocomplete="off"
                               class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开户行 :</label>
                    <div class="layui-input-inline">
                        <input type="text" name="bankName" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span style="color: red">*</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开户人 :</label>
                    <div class="layui-input-inline">
                        <input type="text" name="accountHolder" autocomplete="off" class="layui-input">
                    </div>

                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">开户卡号:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="bankAccount" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <!--            <div class="layui-form-item">-->
            <!--                <div class="layui-inline">-->
            <!--                    <label class="layui-form-label">上传身份证图片（正反面） :</label>-->
            <!--                    <div class="layui-input-inline">-->
            <!--                        <input type="file" name="idphoto">-->
            <!--                    </div>-->

            <!--                </div>-->
            <!--                <div class="layui-inline">-->
            <!--                    <label class="layui-form-label">上传银行卡图片</label>-->
            <!--                    <div class="layui-input-inline">-->
            <!--                        <input type="file" name="bankphoto">-->
            <!--                    </div>-->
            <!--                </div>-->
            <!--            </div>-->


            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">收货地址:</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" name="userAddress" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>


        </form>


    </div>
</div>
<script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>



    layui.use(['form', 'jquery', 'layedit', 'laydate'], function () {
        var form = layui.form
            , $ = layui.jquery
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        $.ajax({
            url: "http://192.168.100.222:8082/user/checking.do",
            type: "post",
            dataType: "json",
            success: function (rec) {
                if (rec.code !== 0) {
                    layer.msg("非管理员无权访问用户注册页面,请联系管理员", {icon: 5, time: 1500}, function () {
                        window.location.href = "/html/welcome.html?t=1";
                    })
                } else {
                    init();
                }
            }
        });


        function init() {

            $.ajax({
                url: "http://192.168.100.222:8082/role/findAllRole.do",
                type: "post",
                dataType: "json",
                data: {page: -1, limit: -1},
                success: function (rec) {
                    if (rec.code !== 0) {
                        layer.msg("初始化数据失败", {icon: 5, time: 1500})
                    } else {
                        $('#roleId').empty();
                        $('#roleId').append(new Option("请选择角色", ""));
                        $.each(rec.data, function (index, item) {
                            $('#roleId').append(new Option(item.roleName, item.id));// 下拉菜单里添加元素
                        });
                        form.render("select");
                    }
                }
            });

            $.ajax({
                url: "http://192.168.100.222:8082/user/findRefer.do",
                type: "post",
                dataType: "json",
                success: function (rec) {
                    if (rec.code !== 0) {
                        $('#refer').append(new Option("暂无数据", ""));// 下拉菜单里添加元素
                    } else {
                        $('#refer').empty();
                        $('#refer').append(new Option("请选择推荐人", ""));
                        $.each(rec.data, function (index, item) {
                            $('#refer').append(new Option(item.username, item.id));// 下拉菜单里添加元素
                        });
                        form.render("select");
                    }
                }
            });

            $.ajax({
                url: "http://192.168.100.222:8082/user/findAllDictionary.do",
                type: "post",
                dataType: "json",
                data: {type: "证件类型"},
                success: function (rec) {
                    if (rec.code !== 0) {
                        $('#cardTypeName').append(new Option("暂无数据", ""));// 下拉菜单里添加元素
                    } else {
                        $('#cardTypeName').empty();
                        $('#cardTypeName').append(new Option("请选择证件类型", ""));
                        $.each(rec.data, function (index, item) {
                            $('#cardTypeName').append(new Option(item.valueName, item.valueName));// 下拉菜单里添加元素
                        });
                        form.render("select");
                    }
                }
            });
            //监听提交
            form.on('submit(demo1)', function (data) {
                $.ajax({
                    url: "http://192.168.100.222:8082/user/register.do",
                    type: "get",
                    data: form.val("register"),
                    dataType: "json",
                    success: function (rec) {
                        if (rec.code === 0) {
                            layer.msg("注册成功", {icon: 6, time: 1000});
                            return false;
                        } else {
                            layer.msg("注册失败", {icon: 5, time: 1000});
                            return false;
                        }
                    }
                });
                alert(111);
                return false;
            });
        }

    });
</script>

</body>
</html>